package com.schillerchina.baselibrary.utils;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangzhiguo
 * @date 2020/7/10 11:23 AM
 * @Description: 滤波器工具类
 */
public class FilterUtils {

    static float[] LP_B2 = {0.0015f, 0.0061f, 0.0091f, 0.0061f, 0.0015f};

    static float[] LP_A2 = {1f, -2.8267f, 3.1210f, -1.5742f, 0.3043f};

    public static float[] filter35Hz(List<Float> filterPar) {
        float[] filter35Hz = new float[filterPar.size()];
        for (int i = 0; i < filterPar.size(); i++) {
            for (int j = 0; i >= j && j <= LP_B2.length - 1; j++) {
                filter35Hz[i] += LP_B2[j] * filterPar.get(i - j) - LP_A2[j] * filter35Hz[i - j];
            }

        }
        filter35Hz[0]=filterPar.get(0);
        filter35Hz[1]=filterPar.get(1);
        return filter35Hz;
    }

    private static List<Float> FloatToList(float[] filter) {
        List<Float> floatList = new ArrayList<>();
        for (float fl : filter) {
            floatList.add(fl);
        }
        return floatList;
    }
    private static String FloatToString(float[] filter) {
        String floatStr = "";
        for (float fl : filter) {
            floatStr=floatStr+fl+",";
        }
        return floatStr;
    }
}